package com.yunzhi.net.api;

import android.text.TextUtils;
import android.util.Log;

import com.cloudknow.utils.StringUtils;
import com.yunzhi.net.utils.AppConfig;
import com.yunzhi.net.utils.DeviceUtils;
import com.yunzhi.net.utils.MetaDataUtils;
import com.yunzhi.net.utils.Utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Author by Mr.Meng
 * created 2019/5/16
 *
 * @desc 公共参数
 */
public class BaseApiService {

    /**
     * 公共参数初始化的地方
     */
    protected Map<String, Object> getPublicParams() {
        String access_token = AppConfig.getAppConfig().getToken(Utils.getApp());
        Map<String, Object> map = new HashMap<>();
//        map.put("access_token", "a4122af5c2d9a5ba40e008dadcc8e24e82bab662");
        map.put("access_token", access_token);
        map.put("app_type", "android");
        map.put("app_type_name", "安卓");//老万说改成安卓
        map.put("device_brand", DeviceUtils.getDeviceBrand() + "." + DeviceUtils.getSystemModel());
        map.put("v", "android_" + DeviceUtils.getInsatance().getVersion(Utils.getApp()));
        map.put("meid", DeviceUtils.getInsatance().getIMEI(Utils.getApp()));
        map.put("network_status", DeviceUtils.getAPNType(Utils.getApp()));
        map.put("os", "android_" + DeviceUtils.getInsatance().getSystemVersion());
        map.put("channel", TextUtils.isEmpty(MetaDataUtils.getMetaDataInApp("UMENG_CHANNEL")) ? "common" : MetaDataUtils.getMetaDataInApp("UMENG_CHANNEL"));
        Log.e("token========",map.get("access_token").toString());
//        Constants.token = "7f256516e95bb691624ab8e8c54e489892da4627";
        return map;
    }

    /**
     * 累加参数的接口
     */
    protected Map<String, Object> putParams(Map<String, Object> map, String key, String value) {
        if (StringUtils.isEmpty(value)) {
            map.put(key, value);
        }
        return map;
    }

    /**
     * 累加参数的接口
     * 此接口以便衍生排序加密
     */
    protected Map<String, Object> putParams(Map<String, Object> map) {
        Map<String, Object> map1 = getPublicParams();
        if (map != null) {
            map1.putAll(map);
        }
//        LogUtils.wTag("参数==",new Gson().toJson(map1));
        return map1;
    }
}
